/* ==============================================================================
Project Name	: 6-Axis controller for robotic arm with 3 phase motor

Model Number	: FD0B098

File Name		: Project_Settings.h

Description		: System parameters configration.

=================================================================================
 History:

 Date			Version			Remarks
---------------------------------------------------------------------------------

============================================================================== */

#ifndef _SETTINGS_H_
#define _SETTINGS_H_

/*** DEFINES *******************************************************************/
// CONSTANTS //
#define PI 						3.14159265358979

// SYSTEM CLOCK CONFIG //
#define SYSTEM_FREQUENCY		200000000									// System Frequency : 200MHz
#define CTRL_LOOP_FREQUENCY 	10000										// Control loop frequency: 10kHz
#define SAMPLING_PERIOD			1 / CTRL_LOOP_FREQUENCY						// Control loop sampling period: 100us
#define CTRL_CYCLE_PER_FRAME	20											// Number of control cycles per frame

// JOINT CONFIG //
#define NUM_OF_JOINTS 			6											// Number of joints/axis of the robotic arm

// EPWM & SYNC PULSE //
#define	EPWM1_TIMER_TBPRD		5000										// EPWM1 TBCLK runs at 50MHz
#define EPWM1_PULSE_PERIOD		150											// EPWM1 SYNC pulse width: 3us

// SCI-B CONFIG //
#define BAUD_RATE				6000000										// SCI-B Baud rate: 6Mbps
#define READ_BYTES 				160											// 160 bytes to read from PC
#define WRITE_BYTES 			64     										// 64 bytes to send to PC


/*** TYPEDEFS ******************************************************************/
typedef enum
{
	FALSE = 0,
	TRUE  = !FALSE
} BOOL_T;

typedef enum
{
	DISABLE = 0,
	ENABLE  = !DISABLE
} STATE_T;


typedef enum
{
	FAIL = 0,
	SUCCESS = !FAIL
} RESULT_T;


/*** MOTOR PARAMETERS DEFINITION ***********************************************/
#define MOTOR_ESTUN		1
#define MOTOR_SANYO		0		// Default motor used

#define	MOTOR_TO_USE	MOTOR_SANYO

#if (MOTOR_TO_USE == MOTOR_ESTUN)
	// Estun Motor //
	#define RS 		2.35		    	    // Stator resistance (ohm)
	#define RR   			               	// Rotor resistance (ohm)
	#define LS   	0.0065					// Stator inductance (H)
	#define LR   			  				// Rotor inductance (H)
	#define LM   			   				// Magnatizing inductance (H)
	#define POLES  	8						// Number of poles
#else
	// Sanyo Motor //
	#define RS 		1.8		    	    	// Stator resistance (ohm)
	#define RR   			               	// Rotor resistance (ohm)
	#define LS   	0.018					// Stator inductance (H)
	#define LR   			  				// Rotor inductance (H)
	#define LM   			   				// Magnatizing inductance (H)
	#define POLES  	2						// Number of poles
#endif


// Define the base quantites //
#define BASE_VOLTAGE    236.14        	// Base peak phase voltage (volt), Vdc/sqrt(3)
#define BASE_CURRENT    20            	// Base peak phase current (amp), Max. measurable peak curr.
#define BASE_TORQUE     		      	// Base torque (N.m)
#define BASE_FLUX       			  	// Base flux linkage (volt.sec/rad)
#define BASE_FREQ      	200           	// Base electrical frequency (Hz)


#endif /* _SETTINGS_H_ */

